package com.corpgovernment.organization.dataloader;

import com.corpgovernment.api.train.soa.TrainOrderClient;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.common.dto.AllOrderBudgetRequestDto;
import com.corpgovernment.common.dto.AllOrderBudgetResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

@Slf4j
@Component
public class TrainOrderClientLoader {

    @Autowired
    private TrainOrderClient trainOrderClient;

    public AllOrderBudgetResponseDto getTrainPassData (List<Long> orderList) {
        AllOrderBudgetRequestDto requestVo = new AllOrderBudgetRequestDto();
        requestVo.setOrderIds(orderList);

        JSONResult<AllOrderBudgetResponseDto> orderInfoByOrderId = trainOrderClient.getTrainOrderByOrderId(requestVo);

        if (orderInfoByOrderId == null || orderInfoByOrderId.getData() == null) {
            log.warn("查询支付单数据异常:" + Optional.ofNullable(orderInfoByOrderId).map(JSONResult::getMsg).orElse("接口无响应"));
            return new AllOrderBudgetResponseDto();
        }
        return orderInfoByOrderId.getData();
    }
}
